/*
 * @Author: wwl 2967796480@qq.com
 * @Date: 2023-09-12 13:42:17
 * @LastEditors: wwl 2967796480@qq.com
 * @LastEditTime: 2023-09-13 15:29:41
 * @FilePath: \LHPerformance-H5\src\main.ts
 * @Description:
 *
 * Copyright (c) 2023 by ${git_name_email}, All Rights Reserved.
 */
import {createApp, createVNode, defineComponent} from 'vue'
import 'vue-global-api' // 解决vue3 composition api 在每个vue文件内重复调用问题
import App from './App'
import router from './router'
import store from './store'
/* Pinia */
import Pinia from './pinia/index.js'
import './index.css'
import './css/font.css'
import './css/animation.css'
import './css/app.less'
import './css/elementPlus.css'
import './css/iconfont.css'
import './css/antDesignVue.less'
import './css/echarts.less'
import lazyPlugin from 'vue3-lazy'
import globalRegister from './libs/global/index'
import Antd, {message, Modal} from 'ant-design-vue'
import './assets/font/font.css'
import './assets/iconfont/iconfont.css'
import {createVersionPolling} from 'version-polling'
import {ExclamationCircleOutlined} from '@ant-design/icons-vue'

// VConsole
// import VConsole from 'vconsole'

// message.success(window.location.href)

// const vConsole = new VConsole()

createVersionPolling({
  appETagKey: '__APP_ETAG__',
  pollingInterval: 1000, // 单位为毫秒
  // silent: process.env.NODE_ENV === "development", // 开发环境下不检测
  onUpdate: self => {
    console.log('#self', self)

    // 当检测到有新版本时，执行的回调函数，可以在这里提示用户刷新页面
    // const result = confirm("页面有更新，点击确定刷新页面！");
    // if (result) {
    //   self.onRefresh();
    // } else {
    //   self.onCancel();
    // }

    console.log('提示')

    Modal.confirm({
      title: '提示',
      icon: createVNode(ExclamationCircleOutlined),
      content: createVNode('div', {style: 'color:black;'}, '页面有更新，点击确定刷新页面！'),
      onOk() {
        console.log('OK')
        self.onRefresh()
        // ElMessage({
        //   type: "success",
        //   message: `更新成功!`,
        // });
      },
      onCancel() {
        console.log('Cancel')
      },
      class: 'update_modal'
    })
    // message.
  }
})

const app = createApp(App)

app.use(lazyPlugin, {
  loading: 'http://d.lohand.com:1111/images/ConstantBlueCloud/WEB/placeholder.png', //图片加载中时显示的默认图片
  error: 'http://d.lohand.com:1111/images/ConstantBlueCloud/WEB/placeholder-error.png' //图片加载失败后显示的图片
})

/**注册 */
app.use(globalRegister)
app.use(Antd)
app.use(store)
app.use(Pinia)
app.use(router)
app.mount('#app')
